Bug 691921 - GTK+ built on Leopard references [NSMenu removellItems]
authorJohn Ralls <jralls@ceridwen.us>
Mon, 20 May 2013 22:15:11 +0000 (15:15 -0700)
committerJohn Ralls <jralls@ceridwen.us>
Mon, 20 May 2013 22:17:47 +0000 (15:17 -0700)
Test it with respondsToSelector, and if it isn't available delete the
items one at a time.

gtk/gtkmodelmenu-quartz.c

index 2f05eac7d05ef2513b5f0f22646833ac1e16b6d7..dae2376ee1e7830dad450aca8658180fba33ce84 100644 (file)
@@ -313,7 +313,19 @@ gtk_quartz_clear_main_menu (void)
 
 - (void)populate
 {
-  [self removeAllItems];
+  /* removeAllItems is available only in 10.6 and later, but it's more
+     efficient than iterating over the array of
+     NSMenuItems. performSelector: suppresses a compiler warning when
+     building on earlier OSX versions. */
+  if ([self respondsToSelector: @selector (removeAllItems)])
+    [self performSelector: @selector (removeAllItems)];
+  else
+    {
+      /* Iterate from the bottom up to save reindexing the NSArray. */
+      int i;
+      for (i = [self numberOfItems]; i > 0; i--)
+       [self removeItemAtIndex: i];
+    }
 
   [self appendFromModel:model withSeparators:with_separators];
 }